package git.soulbgm.controller;

import git.soulbgm.common.base.BaseController;
import git.soulbgm.common.pojo.Response;
import git.soulbgm.pojo.SysConfigParam;
import git.soulbgm.service.SysConfigParamService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 系统参数信息控制器
 *
 * @author SoulBGM
 * @date 2022/07/13 17:40
 */
@RestController
@RequestMapping("system/config/param")
public class SysConfigParamController extends BaseController {

    private final SysConfigParamService sysConfigParamService;

    public SysConfigParamController(SysConfigParamService sysConfigParamService) {
        this.sysConfigParamService = sysConfigParamService;
    }

    @GetMapping("get")
    public Response get(Long code) {
        return success(sysConfigParamService.findByCode(code));
    }

    @PostMapping("add")
    public Response add(SysConfigParam info) {
        boolean result = sysConfigParamService.save(info);
        return result ? success() : error();
    }

    @PostMapping("remove")
    public Response remove(String ids) {
        boolean result = sysConfigParamService.removeByIds(Arrays.asList(ids.split(",")));
        return result ? success() : error();
    }

    @PostMapping("edit")
    public Response edit(SysConfigParam info) {
        boolean result = sysConfigParamService.updateById(info);
        return result ? success() : error();
    }

}
